﻿///初始化上传控件
var qhwUpload = qhwUpload.getInstance({
    uploadUrl: "/CommonAshx/QHWUploadHandler.ashx?alumsId=" + $("#ddlalums").val() + "&m=" + Math.random(),
    placeHoldId: "uploadBtn",
    button_image_url: "/JS/swfUploadImg/XPButtonUploadText_61x22.png" || args.button_image_url,
    file_size_limit: "5 MB",
    file_queue_limit: 4,
    fileQueued: function (file) {
        var fileName = file.name;
        if (fileName.indexOf(",") >= 0) {
            return;
        }
        $("#divprogresscontainer").show();
        var content = $("<div class='lod'><span class='fl'>" + file.name + "</span><div class='loding'><div class='lodingbg' style='width:0%;' id='div_progress" + file.index + "'></div></div><span class='fl' id='uppercent" + file.index + "'>( 等待上传中... )</span></div>");
        $("#divprogresscontainer").append(content);
    },
    uploadSuccess: function (file, serverData) {
        InsertFile(serverData, file.name);

    },
    fileDialogComplete: function (numFilesSelected, numFilesQueued, numFilesInQueue) {
        this.startUpload();
    },
    fileQueueError: function (file, errorCode, message) {
        var errorMessage = "";
        switch (errorCode) {
            case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
                errorMessage = "每次仅能上传4个文件!";
                break;
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                errorMessage = "每个文件不能超过5 MB!";
                break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
            case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
            default:
                errorMessage = "请选择正确的文件格式!";
                break;

        }
        art.dialog({ title: "提示", icon: "error", content: errorMessage });
    },
    uploadProgress: function (file, bytesLoaded, bytesTotal) {
        var percent = Math.ceil((bytesLoaded / bytesTotal) * 100) + "%";

        var thisProgress = $("#div_progress" + file.index);
        if (thisProgress) {
            thisProgress.css("width", percent);
        }
        var thisPercent = $("#uppercent" + file.index)
        if (thisPercent) {
            thisPercent.html(percent);
        }

    }
});
 